package com.example.vadin_demo;

import com.vaadin.annotations.Theme;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

@SuppressWarnings("serial")
@Theme("vadin_demo")
public class Principal extends UI {

	
	
	@Override
	protected void init(VaadinRequest request) {
		
		final VerticalLayout layout = new VerticalLayout();
		setContent( layout );
		layout.setSizeFull();
		
		//Composite add = new  Composite();
		//layout.addComponent( add );
		
		final MenuBar menubar = new MenuBar();
		menubar.setWidth("100.0%");
		layout.addComponent(menubar);
		MenuBar.MenuItem menuMantenimientos = menubar.addItem("Mantenimientos", null, null);
		final Label selection = new Label("-");
		layout.addComponent(selection);
		
		MenuBar.Command mycommand = new MenuBar.Command() {
			@Override
		    public void menuSelected(com.vaadin.ui.MenuBar.MenuItem selectedItem) {
		        selection.setValue("Ordered a " + selectedItem.getText() + " from menu.");
		        if( selectedItem.getText().equals("Nueva Impresion")){
		        	selection.setValue("di clic a " + selectedItem.getText() + " desde menu.");
		        }
		        if( selectedItem.getText().equals("Usuarios")){
		        	selection.setValue("ahroa di clic a " + selectedItem.getText() + " desde el menu.");
		        }
		    }  
		};
		
		MenuBar.Command cmdCurso = new MenuBar.Command() {
			@Override
		    public void menuSelected(com.vaadin.ui.MenuBar.MenuItem selectedItem) {
		        /*Composite add = new  Composite();
		        layout.removeAllComponents();
		        layout.addComponent(add);*/
				
				Window wind = new Window();
				wind.setModal( false );
				wind.setResizable( false );
				wind.setContent( new CursoNuevo() );
				wind.setCaption("Nuevo Curso");
				wind.setWidth("300px");
				wind.setHeight("300px");
				addWindow( wind );
		        
		    }  
		};
		
		MenuBar.Command cmdPlantilla = new MenuBar.Command() {
			@Override
		    public void menuSelected(com.vaadin.ui.MenuBar.MenuItem selectedItem) {
		        
				Window wind = new Window();
				wind.setModal( false );
				wind.setResizable( false );
				wind.setContent( new  PlantillaNueva() );
				wind.setCaption("Nueva Plantilla");
				wind.setWidth("400px");
				wind.setHeight("300px");
				addWindow( wind );
		        
		    }  
		};
		
		menuMantenimientos.addItem("Cursos", null, null)
			.addItem("Nuevo Curso", null, cmdCurso);
		menuMantenimientos.addItem("Plantillas", null, null)
		.addItem("Nueva Plantilla", null, cmdPlantilla);
		
		MenuBar.MenuItem cold_beverages = menuMantenimientos.addItem("Cold", null, null);
			cold_beverages.addItem("Milk", null, mycommand);

			// Another top-level item
		menubar.addItem("Impresiones", null, null)
			.addItem("Nueva Impresion", null, mycommand);

			// Yet another top-level item
		menubar.addItem("Administracion", null, null)
			.addItem("Usuarios", null, mycommand);
			
		
		Button button = new Button("Click Me");
		button.addClickListener(new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				layout.addComponent(new Label("Thank you for clicking"));
			}
		});
		layout.addComponent(button);
		
	}

}